package com.zhuzi.demo.service;

import javax.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zhuzi.demo.bean.User;
import com.zhuzi.demo.dao.test1.UserDao1;
import com.zhuzi.demo.dao.test2.UserDao2;

@Service
@Transactional(value=Transactional.TxType.REQUIRED,rollbackOn=Exception.class)
public class UserService {
	@Autowired
	private UserDao1 userDao1;
	@Autowired
	private UserDao2 userDao2;
	
	public void addUser1(String userName, String password, String phone) throws Exception{
		User user = new User();
		user.setUserName(userName);
		user.setPassword(password);
		user.setPhone(phone+"-1");
		userDao1.insert(user);
		
		User user1 = new User();
		user1.setUserName(userName);
		user1.setPassword(password);
		user1.setPhone(phone+"-2");
		userDao2.insert(user1);
		
		int i = 1/0;
	}

	public void addUser2(String userName, String password, String phone) throws Exception{
		User user = new User();
		user.setUserName(userName);
		user.setPassword(password);
		user.setPhone(phone);
		userDao2.insert(user);
	}
}